# Copyright (c) 2008 Alvin Wang http://cloudwizard.com/
# License New BSD
# See README for additional information

from cloudwizard.ssh import Connection
from cloudwizard.cwobject import CWobject
import os

class ComputeService(CWobject):
    """A compute Service is about CPUs.  There is usually some disk included.

    Windows scripting
    http://www.singularity.be/2008/03/using-rdesktop-to-script-windows.html
    http://repository.maemo.org/extras-devel/pool/diablo/free/p/pyrdesktop/pyrdesktop_1.5.0-4_all.deb

    eg] EC2,
    """
    # static - must be overridden
    cloud_interactive = None        # ssh key, ssh password, RDP
    cloud_filetransfer = None        # ssh, ftp, RDP
    cloud_name = None
    cloud_opsys = None        # win32, linux, solaris, BSD, MacOs
    # config
    cloud_config = None
    cloud_auth = None

    def __init__(self, config=None, **args):  # set variables
        """Initial Object"""
        self.cloud_config = config      # not sure what to do with this
            
    def create(self, config=None, **args):  # set variables
        """override me"""
        pass
        
    def delete(self, config=None, **args):  # set variables
        """override me"""
        pass

    def olist(self, config=None, **args):  # set variables
        """override me"""
        pass
        
    def find(self):
        """return a device object or None
        """
        pass
                

class ComputeDevice(CWobject):
    """A compute device is a CPU.  There is usually some disk included."""
    cloud_user = None
    cloud_password = None
    cloud_keyfile = None
    cloud_ip_address = None
    dns_address=None

    def __init__(self, dns_address=None, ip=None, name=None):  # set variables
        """Initialize Device"""
        if dns_address != None:
            self.dns_address = dns_address

    def get_ssh(self, username=None, private_key=None, password=None):
        """Get the ssh connection object
        """     
        if password:
            # Using Password.
            return Connection(self.dns_address, username=username, 
                password=password)
        else:
            return Connection(self.dns_address, username=username, 
                private_key=private_key)

    def wait_ssh(self, vm_ip=None, timeout=0, delay=60, **args):
        print "here"

    def wait_status(self, **args):
        # status - disk file, ec2
        print "here"

    def status(self, **args):
        """Get status a device"""
        # status - disk file, ec2
        print "here"
